*****This do file checks robustness of the results by employment size of all subsidiaries that each parent owns
*****Separate firm samples into 2 groups by their employment size and estimate each
*****Note subsidiaries of some parents have no info on employees.
*****Those parent companies are dropped from estimation, so sample numbers must different than baseline analysis

clear

set mem 100m
set matsize 4000
set more off

local evt_window = 10 /*Define the width of event dates to include as event day dummies*/
local estwindow = 180
local evtwindow = 30
local EVENT  "majorinitiative1summit" /*majorinitiative1, majorinitiative2, majorinitiative1summit, or majorinitiative2alt*/
local eveyear  "all" /*For majorinitiative1&2, estimate each event in 1996, 1999, 2005 separately, or all*/
local thintrade    = 0 /*0 (No thin trade) or 1*/
local controlevents = 1
local controlindustry = 1
local suffix "20090224"

use data_event_study_before_estimation_T_`estwindow'_`evtwindow'_thin`thintrade'_`EVENT', clear

sort ticker date
merge ticker date using Subsidiaries_employment_adjusted_holdings, nok
drop _merge


*CREATE EVENT YEAR
gen tmp = year if event_trading_time==0
egen eventyear = min(tmp), by(panel_id)
drop tmp
//keep if eventyear==1996

sort ticker eventyear
merge ticker eventyear using employment_per_year_parents_imputed, nok keep(employment)
drop _merge


rename employment Employment

sort ticker
merge ticker using employment_parents, nok keep(employment)
drop _merge

replace Employment = employment if Employment==. & employment~=.
drop employment
rename Employment employment


gen relative_employ = total_employ_adjh/employment


if "`EVENT'"=="majorinitiative1" |"`EVENT'"=="majorinitiative1summit"  {
    drop if ticker=="GND" & eventyear==1996
    drop if event_time<-122 | event_time==. /*To be comparable to the portfolio approach*/
}
if "`EVENT'"=="majorinitiative2" | "`EVENT'"=="majorinitiative2alt" {
    drop if ticker=="ANG" & eventyear==1999
    drop if event_time<-122 | event_time==. /*To be comparable to the portfolio approach*/
}



egen oneobsfirm = tag(panel_id)
qui su relative_employ if oneobsfirm, d
local medemploy = r(p50)
gen largeall = relative_employ>`medemploy' if relative_employ~=.

levelsof eventyear, local(years)
foreach y of local years {
    qui su relative_employ if oneobsfirm & year==`y', d
    local medemploy`y' = r(p50)
    count if relative_employ>`medemploy`y'' & relative_employ~=. & oneobsfirm
    local above = r(N)
    count if relative_employ>=`medemploy`y'' & relative_employ~=. & oneobsfirm
    local abovequal = r(N)
    count if relative_employ~=. & oneobsfirm
    local total = r(N)
    local dist1 = abs(`above' - `total'/2)
    local dist2 = abs(`abovequal' - `total'/2)
    if `dist1'<=`dist2' {
        gen large`y' = relative_employ>`medemploy`y'' if relative_employ~=.
    }
    else if `dist1'<=`dist2' {
        gen large`y' = relative_employ>=`medemploy`y'' if relative_employ~=.
    }
}



if "`eveyear'" == "1996" {
    keep if eventyear==1996
}
if "`eveyear'" == "1999" {
    keep if eventyear==1999
}
if "`eveyear'" == "2005" {
    keep if eventyear==2005
}


if `controlindustry'==1 {
        if `thintrade'==0 {
            local industry "R_group"
        }
        else if `thintrade'==1 {
            local industry "Rindtt"
        }
}


local action ""
replace corporate_action = "0" if corporate_action==""


if `controlindustry'==1 {
    local industrycontrols "i.panel_id|`industry'"
}
else if `controlindustry'==0 {
    local industrycontrols ""
}

tab event_time if abs(event_time)<=`evt_window' & event_window==1, gen(Devent)
local neventdummies = 2*`evt_window'+1
forv i==1/`neventdummies' {
        replace Devent`i' = 0 if Devent`i' == .
}

drop if event_time > `evt_window'
*exit


su event_time
local mintime = r(min)

matrix A1 = J(`neventdummies',6,.)


*=======================================================================================================
*REGRESSIONS with all coefficients panel_id specific (except event time dummies)
*=======================================================================================================

*I. NO-THIN TRADE ISSUES
*-------------------------------------------------------------------------------------------------------

if `thintrade'== 0 {
*================================================================================
*1. Baseline specification (i.e., no addiitonal time dummy variables)
*================================================================================

***Group with smaller asset size***
    xi: reg  R  i.panel_id*Rm  `industrycontrols'  i.panel_id*i.corporate_action  Devent* if event_time>=`mintime' & large`eveyear'==0, cluster(date) r

    local diff10 = (_b[Devent11]+_b[Devent12]+_b[Devent13]+_b[Devent14]+_b[Devent15]+_b[Devent16]+_b[Devent17]+_b[Devent18]+_b[Devent19]+_b[Devent20]+_b[Devent21])/11 ///
              - (_b[Devent1]+_b[Devent2]+_b[Devent3]+_b[Devent4]+_b[Devent5]+_b[Devent6]+_b[Devent7]+_b[Devent8]+_b[Devent9]+_b[Devent10])/10
    test (Devent1+Devent2+Devent3+Devent4+Devent5+Devent6+Devent7+Devent8+Devent9+Devent10)/10 ///
        = (Devent11+Devent12+Devent13+Devent14+Devent15+Devent16+Devent17+Devent18+Devent19+Devent20+Devent21)/11
    local F1 = r(F)
    local p1 = r(p)

    local diff5 = (_b[Devent11]+_b[Devent12]+_b[Devent13]+_b[Devent14]+_b[Devent15]+_b[Devent16])/6 ///
              - (_b[Devent6]+_b[Devent7]+_b[Devent8]+_b[Devent9]+_b[Devent10])/5
    test (Devent6+Devent7+Devent8+Devent9+Devent10)/5 = (Devent11+Devent12+Devent13+Devent14+Devent15+Devent16)/6
    local F2 = r(F)
    local p2 = r(p)

    local diff3 = (_b[Devent11]+_b[Devent12]+_b[Devent13]+_b[Devent14])/4 - (_b[Devent8]+_b[Devent9]+_b[Devent10])/3
    test (Devent8+Devent9+Devent10)/3 = (Devent11+Devent12+Devent13+Devent14)/4


    outreg Devent* using Regression_Approach_robust_relative_employ_`eveyear'_`EVENT'.txt, se 3aster coefast nolabel ctitle(`mintime'_0) ///
    addstat(-10to-1vs0to10, `diff10', F test, `F1', Prob>F, `p1', -5to-1vs0to5, `diff5', F test, `F2', Prob>F, `p2', -3to-1vs0to3, `diff3', F test,  r(F), Prob>F, r(p)) ///
    adec(5, 3, 3, 5, 3, 3, 5, 3, 3) replace


    *Building CAR and their standard errors

    forv i==1/`neventdummies' {
        if `i'==1 {
            matrix A1[`i',1] = _b[Devent1]
            matrix A1[`i',2] = _se[Devent1]
            matrix A1[`i',3] = 2*ttail(e(df_r),abs(_b[Devent1]/_se[Devent1]))
        }
        else {
            local exp "Devent1"

            forv j == 2/`i' {
                local exp "`exp' + Devent`j'"
            }

            qui lincom `exp'
            matrix A1[`i',1] = r(estimate)
            matrix A1[`i',2] = r(se)
            matrix A1[`i',3] = 2*ttail(r(df),abs(r(estimate)/r(se)))
        }
    }

***Group with larger asset size***
    xi: reg  R  i.panel_id*Rm  `industrycontrols'  i.panel_id*i.corporate_action  Devent* if event_time>=`mintime' & large`eveyear'==1, cluster(date) r

    local diff10 = (_b[Devent11]+_b[Devent12]+_b[Devent13]+_b[Devent14]+_b[Devent15]+_b[Devent16]+_b[Devent17]+_b[Devent18]+_b[Devent19]+_b[Devent20]+_b[Devent21])/11 ///
              - (_b[Devent1]+_b[Devent2]+_b[Devent3]+_b[Devent4]+_b[Devent5]+_b[Devent6]+_b[Devent7]+_b[Devent8]+_b[Devent9]+_b[Devent10])/10
    test (Devent1+Devent2+Devent3+Devent4+Devent5+Devent6+Devent7+Devent8+Devent9+Devent10)/10 ///
        = (Devent11+Devent12+Devent13+Devent14+Devent15+Devent16+Devent17+Devent18+Devent19+Devent20+Devent21)/11
    local F1 = r(F)
    local p1 = r(p)

    local diff5 = (_b[Devent11]+_b[Devent12]+_b[Devent13]+_b[Devent14]+_b[Devent15]+_b[Devent16])/6 ///
              - (_b[Devent6]+_b[Devent7]+_b[Devent8]+_b[Devent9]+_b[Devent10])/5
    test (Devent6+Devent7+Devent8+Devent9+Devent10)/5 = (Devent11+Devent12+Devent13+Devent14+Devent15+Devent16)/6
    local F2 = r(F)
    local p2 = r(p)

    local diff3 = (_b[Devent11]+_b[Devent12]+_b[Devent13]+_b[Devent14])/4 - (_b[Devent8]+_b[Devent9]+_b[Devent10])/3
    test (Devent8+Devent9+Devent10)/3 = (Devent11+Devent12+Devent13+Devent14)/4


    outreg Devent* using Regression_Approach_robust_relative_employ_`eveyear'_`EVENT'.txt, se 3aster coefast nolabel ctitle(`mintime'_1) ///
    addstat(-10to-1vs0to10, `diff10', F test, `F1', Prob>F, `p1', -5to-1vs0to5, `diff5', F test, `F2', Prob>F, `p2', -3to-1vs0to3, `diff3', F test,  r(F), Prob>F, r(p)) ///
    adec(5, 3, 3, 5, 3, 3, 5, 3, 3) append


    *Building CAR and their standard errors

    forv i==1/`neventdummies' {
        if `i'==1 {
            matrix A1[`i',4] = _b[Devent1]
            matrix A1[`i',5] = _se[Devent1]
            matrix A1[`i',6] = 2*ttail(e(df_r),abs(_b[Devent1]/_se[Devent1]))
        }
        else {
            local exp "Devent1"

            forv j == 2/`i' {
                local exp "`exp' + Devent`j'"
            }

            qui lincom `exp'
            matrix A1[`i',4] = r(estimate)
            matrix A1[`i',5] = r(se)
            matrix A1[`i',6] = 2*ttail(r(df),abs(r(estimate)/r(se)))
        }
    }
}



*II. THIN TRADE ISSUES
*-------------------------------------------------------------------------------------------------------


if `thintrade'== 1 {

*================================================================================
*1. Baseline specification (i.e., no addiitonal time dummy variables)
*================================================================================

***Group with smaller asset size***
    xi: reg  Rtt  i.panel_id*ntt  i.panel_id|Rmtt  `industrycontrols'  i.panel_id*i.corporate_action  Devent* if event_time>=`mintime' & large`eveyear'==0, cluster(date) r

    local diff10 = (_b[Devent11]+_b[Devent12]+_b[Devent13]+_b[Devent14]+_b[Devent15]+_b[Devent16]+_b[Devent17]+_b[Devent18]+_b[Devent19]+_b[Devent20]+_b[Devent21])/11 ///
              - (_b[Devent1]+_b[Devent2]+_b[Devent3]+_b[Devent4]+_b[Devent5]+_b[Devent6]+_b[Devent7]+_b[Devent8]+_b[Devent9]+_b[Devent10])/10
    test (Devent1+Devent2+Devent3+Devent4+Devent5+Devent6+Devent7+Devent8+Devent9+Devent10)/10 ///
        = (Devent11+Devent12+Devent13+Devent14+Devent15+Devent16+Devent17+Devent18+Devent19+Devent20+Devent21)/11
    local F1 = r(F)
    local p1 = r(p)

    local diff5 = (_b[Devent11]+_b[Devent12]+_b[Devent13]+_b[Devent14]+_b[Devent15]+_b[Devent16])/6 ///
              - (_b[Devent6]+_b[Devent7]+_b[Devent8]+_b[Devent9]+_b[Devent10])/5
    test (Devent6+Devent7+Devent8+Devent9+Devent10)/5 = (Devent11+Devent12+Devent13+Devent14+Devent15+Devent16)/6
    local F2 = r(F)
    local p2 = r(p)

    local diff3 = (_b[Devent11]+_b[Devent12]+_b[Devent13]+_b[Devent14])/4 - (_b[Devent8]+_b[Devent9]+_b[Devent10])/3
    test (Devent8+Devent9+Devent10)/3 = (Devent11+Devent12+Devent13+Devent14)/4

    outreg Devent* using Regression_Approach_robust_relative_employ_thin_`eveyear'_`EVENT'.txt, se 3aster coefast nolabel ctitle(`mintime'_0) ///
    addstat(-10to-1vs0to10, `diff10', F test, `F1', Prob>F, `p1', -5to-1vs0to5, `diff5', F test, `F2', Prob>F, `p2', -3to-1vs0to3, `diff3', F test,  r(F), Prob>F, r(p)) ///
    adec(5, 3, 3, 5, 3, 3, 5, 3, 3) replace


    *Building CAR and their standard errors

    forv i==1/`neventdummies' {
        if `i'==1 {
            matrix A1[`i',1] = _b[Devent1]
            matrix A1[`i',2] = _se[Devent1]
            matrix A1[`i',3] = 2*ttail(e(df_r),abs(_b[Devent1]/_se[Devent1]))
        }
        else {
            local exp "Devent1"

            forv j == 2/`i' {
                local exp "`exp' + Devent`j'"
            }

            qui lincom `exp'
            matrix A1[`i',1] = r(estimate)
            matrix A1[`i',2] = r(se)
            matrix A1[`i',3] = 2*ttail(r(df),abs(r(estimate)/r(se)))
        }
    }

***Group with larger asset size***
    xi: reg  Rtt  i.panel_id*ntt  i.panel_id|Rmtt  `industrycontrols'  i.panel_id*i.corporate_action  Devent* if event_time>=`mintime' & large`eveyear'==1, cluster(date) r

    local diff10 = (_b[Devent11]+_b[Devent12]+_b[Devent13]+_b[Devent14]+_b[Devent15]+_b[Devent16]+_b[Devent17]+_b[Devent18]+_b[Devent19]+_b[Devent20]+_b[Devent21])/11 ///
              - (_b[Devent1]+_b[Devent2]+_b[Devent3]+_b[Devent4]+_b[Devent5]+_b[Devent6]+_b[Devent7]+_b[Devent8]+_b[Devent9]+_b[Devent10])/10
    test (Devent1+Devent2+Devent3+Devent4+Devent5+Devent6+Devent7+Devent8+Devent9+Devent10)/10 ///
        = (Devent11+Devent12+Devent13+Devent14+Devent15+Devent16+Devent17+Devent18+Devent19+Devent20+Devent21)/11
    local F1 = r(F)
    local p1 = r(p)

    local diff5 = (_b[Devent11]+_b[Devent12]+_b[Devent13]+_b[Devent14]+_b[Devent15]+_b[Devent16])/6 ///
              - (_b[Devent6]+_b[Devent7]+_b[Devent8]+_b[Devent9]+_b[Devent10])/5
    test (Devent6+Devent7+Devent8+Devent9+Devent10)/5 = (Devent11+Devent12+Devent13+Devent14+Devent15+Devent16)/6
    local F2 = r(F)
    local p2 = r(p)

    local diff3 = (_b[Devent11]+_b[Devent12]+_b[Devent13]+_b[Devent14])/4 - (_b[Devent8]+_b[Devent9]+_b[Devent10])/3
    test (Devent8+Devent9+Devent10)/3 = (Devent11+Devent12+Devent13+Devent14)/4

    outreg Devent* using Regression_Approach_robust_relative_employ_thin_`eveyear'_`EVENT'.txt, se 3aster coefast nolabel ctitle(`mintime'_1) ///
    addstat(-10to-1vs0to10, `diff10', F test, `F1', Prob>F, `p1', -5to-1vs0to5, `diff5', F test, `F2', Prob>F, `p2', -3to-1vs0to3, `diff3', F test,  r(F), Prob>F, r(p)) ///
    adec(5, 3, 3, 5, 3, 3, 5, 3, 3) append


    *Building CAR and their standard errors

    forv i==1/`neventdummies' {
        if `i'==1 {
            matrix A1[`i',4] = _b[Devent1]
            matrix A1[`i',5] = _se[Devent1]
            matrix A1[`i',6] = 2*ttail(e(df_r),abs(_b[Devent1]/_se[Devent1]))
        }
        else {
            local exp "Devent1"

            forv j == 2/`i' {
                local exp "`exp' + Devent`j'"
            }

            qui lincom `exp'
            matrix A1[`i',4] = r(estimate)
            matrix A1[`i',5] = r(se)
            matrix A1[`i',6] = 2*ttail(r(df),abs(r(estimate)/r(se)))
        }
    }
}


*mat list A1


egen id = group(panel_id)
keep if id==1
keep if event_time>=-10 & event_time<=10
keep event_time
svmat A1, names( col )

rename c1 car0
rename c2 se0
rename c3 p0
rename c4 car1
rename c5 se1
rename c6 p1

gen star0 = car0  if p0 <=0.1
gen star1 = car1  if p1 <=0.1

sort event_time

if `thintrade'== 0 {
    saveold Regression_Approach_CAR_robust_relative_employ_`eveyear'_`EVENT'_`suffix', replace
}
if `thintrade'== 1 {
    saveold Regression_Approach_CAR_robust_relative_employ_thin_`eveyear'_`EVENT'_`suffix', replace
}


*****************************************************************************
*To draw figures of the CAR evolution                           *
*****************************************************************************

if `thintrade' == 1 {
    local thin "_thin"
}

use Regression_Approach_CAR_robust_relative_employ`thin'_`eveyear'_`EVENT'_`suffix', clear

forv n=1/21 {
     replace event_time = `n'-11 in `n'
}

gen ciu0 = car0 + se0*1.64
gen cil0 = car0 - se0*1.64
gen ciu1 = car1 + se1*1.64
gen cil1 = car1 - se1*1.64

twoway (line car0 event_time, lwidth(thick)) ///
(line ciu0 event_time, lpattern(shortdash) lwidth(medthick) lcolor(red)) ///
(line cil0 event_time, lpattern(shortdash) lwidth(medthick) lcolor(red)) ///
, yline(0, lwidth(vvthin)) /*yscale(range(0 0.01))*/ ytitle(Cumulative abnormal return, margin(medium)) xtitle(Event time, margin(medium)) legend(off) /*nodraw*/

gr save Figure_9_A, replace


twoway (line car1 event_time, lwidth(thick)) ///
(line ciu1 event_time, lpattern(shortdash) lwidth(medthick) lcolor(red)) ///
(line cil1 event_time, lpattern(shortdash) lwidth(medthick) lcolor(red)) ///
, yline(0, lwidth(vvthin)) /*yscale(range(0 0.01))*/ ytitle(Cumulative abnormal return, margin(medium)) xtitle(Event time, margin(medium)) legend(off) /*nodraw*/

gr save Figure_9_B, replace
